package com.example.mapper;

import com.example.entity.Volunteer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ASUS
 */
public interface VolunteerMapper {
    void insert(Volunteer volunteer);


    @Select("select * from volunteer where username = #{username}")
    Volunteer selectByUsername(String username);

    @Select("select volunteer.*, city.name as cityName from volunteer left join city on volunteer.pet_id = city.id")
    List<Volunteer> selectAll();

    @Select("select volunteer.*, city.name as cityName from volunteer " +
            "left join city on volunteer.pet_id = city.id " +
            "where name like concat('%',#{name},'%')")
    List<Volunteer> selectByName(String name);

    @Delete("delete from volunteer where id = #{id}")
    void deleteById(Integer id);

    void updateById(Volunteer volunteer);

    @Select("select volunteer.*, city.name as cityName from volunteer " +
            "left join city on volunteer.pet_id = city.id " +
            "where volunteer.id = #{id}")
    Volunteer selectById(Integer id);
}
